package com.xlhj.rabbit.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Author: caijliu
 * @Date: 02/09/2021 15:47
 * @Description TODO
 * @Vsersion: 0.0.1
 */
@RestController
@RequestMapping("/direct")
public class DirectProducerController {

    private static final String DIRECT_EXCHANGE_NAME = "direct-exchange";
    private static final String ROUTING_KEY = "direct.route.key";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendMessage/{message}")
    public void sendMessage(@PathVariable String message) {
        String uuid = UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(DIRECT_EXCHANGE_NAME, ROUTING_KEY, message + ROUTING_KEY, correlationData);
    }
}
